package com.pension.model.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.pension.model.dto.Roomoption;

public class RoomoptionDao {
	
	public Roomoption getRoomsoptionByNumber(int num){
		
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		Roomoption op = null;
		
		try {
			conn = ConnectionHelper.getConnection();
			//3. 명령 생성
			String sql = 
						"SELECT optionno, optionname, priceoption " + 
						"FROM roomsoption " +
						"WHERE optionno = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, num);
			//4. 명령 실행
			rs = pstmt.executeQuery();
			//5. 조회 결과를 처리 (SELECT QUERY인 경우)
			if (rs.next()) {
				op = new Roomoption();
				
				op.setOptionno(rs.getInt(1));
				op.setOptionname(rs.getString(2));
				op.setPriceoption(rs.getInt(3));
			}
			
		} catch (Exception ex) {
			
		} finally {
			try { rs.close(); } catch (Exception ex) {}
			try { pstmt.close(); } catch (Exception ex) {}
			try { conn.close(); } catch (Exception ex) {}
		}
		
		return op;
	}
	
	public List<Roomoption> getRoomsoptionList() {
		
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		ArrayList<Roomoption> optionlist = new ArrayList<Roomoption>();
		
		try {
			conn = ConnectionHelper.getConnection();
			String sql = 
						"SELECT optionno, optionname, priceoption " + 
						"FROM roomsoption";
			pstmt = conn.prepareStatement(sql);						
			//4. 명령 실행
			rs = pstmt.executeQuery();
			//5. 조회 결과를 처리 (SELECT QUERY인 경우)
			while (rs.next()) {
				Roomoption op = new Roomoption();
				
				op.setOptionno(rs.getInt(1));
				op.setOptionname(rs.getString(2));
				op.setPriceoption(rs.getInt(3));
				
				optionlist.add(op);
			}
			
		} catch (Exception ex) {
			
		} finally {
			try { rs.close(); } catch (Exception ex) {}
			try { pstmt.close(); } catch (Exception ex) {}
			try { conn.close(); } catch (Exception ex) {}
		}
		
		return optionlist;
	}
	
}











